﻿using Autodesk.AutoCAD.DatabaseServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XS.Tunnel.Cad.SteelBracing.Component.SteelShotcrete.GrilleComponent;
using XS.Tunnel.Cad.SteelBracing.Component.SteelShotcrete.UniversalBeamComponent;

using XS.Tunnel.Cad.SteelBracing.Infrastructure;
using XS.Tunnel.Cad.SteelBracing.Infrastructure.Extensions;

namespace XS.Tunnel.Cad.SteelBracing.Component.SteelShotcrete
{
    /// <summary>
    /// 拱架抽线
    /// </summary>
    public abstract class AbstractSteelShotcrete:CadBase
    {
        /// <summary>
        /// 暗洞信息
        /// </summary>
        public DarkHoleInfo Info { get; }
        /// <summary>
        /// 参数
        /// </summary>
        public SteelShotcreteParameter Parameter { get;}
        /// <summary>
        /// 拱圈  arch ring
        /// </summary>
        public List<ISysPoint> ArchRing { get; private set; }
       

        /// <summary>
        /// 180度弧，要分割的弧
        /// </summary>
        public Curve Arc180 { get; protected set; }
        /// <summary>
        /// 左边墙
        /// </summary>
        public Curve LeftSideAll { get; protected set; }
        /// <summary>
        /// 右边墙
        /// </summary>
        public Curve RightSideAll { get; protected set; }

        /// <summary>
        /// 左边墙
        /// </summary>
        public Line LeftSideAllLine { get; protected set; }
        /// <summary>
        /// 右边墙
        /// </summary>
        public Line RightSideAllLine { get; protected set; }

        /// <summary>
        /// 分段
        /// </summary>
        public List<Curve> Subsections { get; protected set; } = new List<Curve>();

        /// <summary>
        /// 钢板
        /// </summary>
        public List<Curve> SteelPlateList { get; protected set; } = new List<Curve>();



        /// <summary>
        /// 仰拱路径
        /// </summary>
        public List<ISysPoint> InvertedArchPath { get; private set; }

        /// <summary>
        /// 左仰拱圆弧
        /// </summary>
        public Curve LeftInvertedArc { get; set; }
        /// <summary>
        /// 右仰拱圆弧
        /// </summary>
        public Curve RightInvertedArc { get; set; }

        /// <summary>
        /// 仰拱圆弧， 中间的， 要分割的
        /// </summary>
        public Curve InvertedArc { get; set; }

        /// <summary>
        /// 仰拱分段后
        /// </summary>
        public List<Curve> InvertedArcSubsections { get; protected set; } = new List<Curve>();


        public AbstractSteelShotcrete(DarkHoleInfo info, IList<ISysPoint> pointData, SteelShotcreteParameter parameter)
        {
            parameter.Verification();

            Info = info;
            Parameter = parameter;
            PointInit(pointData);
            Initial();
        }



        protected abstract void Initial();

        /// <summary>
        /// 坐标初始化
        /// </summary>
        /// <param name="pointData"></param>
        public void PointInit(IList<ISysPoint> pointData)
        {
            var outer= pointData.Where(x=>x.BizTpyeCode==StructurePointLocationConstant.PrimarySupportOuterContour).ToList();

            ArchRing = outer.Where(x =>
               x.Code != StructurePointLocationConstant.LeftInvertedArchArc
               && x.Code != StructurePointLocationConstant.InvertedArchArc
               && x.Code != StructurePointLocationConstant.RightInvertedArchArc
               && x.Code != StructurePointLocationConstant.RightHorizon
               && x.Code != StructurePointLocationConstant.LeftHorizon
              ).ToList();


            ISysPoint leftLine = null;
            ISysPoint right = null;
            // 大墙角的左右拱墙
            if (Info.ColumnArchFootType == ColumnArchFootType.LargeCornerJoin)  
            {
                leftLine = ArchRing.Where(x => x.Code == StructurePointLocationConstant.LeftboostVerticalLine).FirstOrDefault();
                right = ArchRing.Where(x => x.Code == StructurePointLocationConstant.RightboostVerticalLine).FirstOrDefault();
            }
            else
            {
                 leftLine = ArchRing.Where(x => x.Code == StructurePointLocationConstant.LeftLine).FirstOrDefault();
                 right = ArchRing.Where(x => x.Code == StructurePointLocationConstant.RightLine).FirstOrDefault();
            }

            if (leftLine != null)
            {
                LeftSideAllLine = leftLine.ToEntity() as Line;
            }
            if (right != null)
            {
                RightSideAllLine = right.ToEntity() as Line;
            }



            InvertedArchPath = outer.Where(x =>
              x.Code == StructurePointLocationConstant.LeftInvertedArchArc
              || x.Code == StructurePointLocationConstant.InvertedArchArc  //invertedArchArc
              || x.Code == StructurePointLocationConstant.RightInvertedArchArc
            ).ToList();


            if (Info.ColumnArchFootType == ColumnArchFootType.LargeCornerJoin)
            { 
                // 大墙角的时候  仰拱的左右的是直线
                var left = outer.Where(x => x.Code == StructurePointLocationConstant.LeftHorizon).FirstOrDefault();
                var rightR = outer.Where(x => x.Code == StructurePointLocationConstant.RightHorizon).FirstOrDefault();

                InvertedArchPath.Add(left);
                InvertedArchPath.Add(rightR);
            }





        }


        public void Print(string msg)
        { 
            Doc.Editor.WriteMessage(msg);   
        }

        public abstract void Build();
        public abstract void Draw(); 

    }
}
